/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.dto;

import cz.muni.fi.pa165.entity.Delivery;
import cz.muni.fi.pa165.transfers.CustomerT;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Jakub Janco, Vlasta Ramik
 */
public final class DeliveryDTO implements Serializable {
    
    private static final long serialVersionUID = 6546541654515L;
    
    private Long id;
    
    private List<PackageDTO> packages;
    
    private Date creationDate;
    
    private Date deliveryDate;
    
    
    private EmployeeDTO deliveryBoy;
    
    private CustomerDTO customer;
    
    private Long deliveryNumber;
    
    private String recipientName;
    
    private String recipientAddress;
    
    private String recipientZip;
    
    private String recipientCity;
    
    public Long getId() {
        return id;
    }

    /**
     * Sets unique id
     * @param id Delivery id
     * @throws IllegalArgumentException if id was set before method called
     */
    public void setId(Long id) {
        if (this.id != null) {
            throw new IllegalArgumentException("id was already set.");
        }
        this.id = id;
    }

    public Date getCreationDate() {
        if (creationDate == null) {
            return null;
        }
        return (Date) creationDate.clone();
    }

    public void setCreationDate(Date creationDate) {
        if (creationDate != null) {
            this.creationDate = new Date(creationDate.getTime());
        }
    }

    public CustomerDTO getCustomer() {
        return customer;
    }

    public void setCustomer(CustomerDTO customer) {
        this.customer = customer;
    }

    public EmployeeDTO getDeliveryBoy() {
        return deliveryBoy;
    }

    public void setDeliveryBoy(EmployeeDTO deliveryBoy) {
        this.deliveryBoy = deliveryBoy;
    }

    public Date getDeliveryDate() {
        if (deliveryDate == null) {
            return null;
        }
        return (Date) deliveryDate.clone();
    }

    public void setDeliveryDate(Date deliveryDate) {
        if (deliveryDate != null) {
            this.deliveryDate = new Date(deliveryDate.getTime());
        }
    }

    public Long getDeliveryNumber() {
        return deliveryNumber;
    }

    public void setDeliveryNumber(Long deliveryNumber) {
        this.deliveryNumber = deliveryNumber;
    }

    /**
     * 
     * @return list of packages, empty list if attribute is null
     */
    public List<PackageDTO> getPackages() {
        if(packages==null) {
            return new ArrayList<PackageDTO>();
        }
        return packages;
    }

    public void setPackages(List<PackageDTO> packages) {
        this.packages = packages;
    }

    public String getRecipientAddress() {
        return recipientAddress;
    }

    public void setRecipientAddress(String recipientAddress) {
        this.recipientAddress = recipientAddress;
    }

    public String getRecipientCity() {
        return recipientCity;
    }

    public void setRecipientCity(String recipientCity) {
        this.recipientCity = recipientCity;
    }

    public String getRecipientName() {
        return recipientName;
    }

    public void setRecipientName(String recipientName) {
        this.recipientName = recipientName;
    }

    public String getRecipientZip() {
        return recipientZip;
    }

    public void setRecipientZip(String recipientZip) {
        this.recipientZip = recipientZip;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DeliveryDTO other = (DeliveryDTO) obj;
        if (this.id == null || !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }  

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "DeliveryDTO{" + "id=" + id + ", packages=" + packages + ", creationDate=" + creationDate + ", deliveryDate=" + deliveryDate + ", deliveryBoy=" + deliveryBoy + ", customer=" + customer + ", deliveryNumber=" + deliveryNumber + ", recipientName=" + recipientName + ", recipientAddress=" + recipientAddress + ", recipientZip=" + recipientZip + ", recipientCity=" + recipientCity + '}';
    }
}
